home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 12004000 / palreq24.lha / Palette.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-29  |  11.4 KB  |  359 lines

  1. /*----------------------------------------------------------------------
  2.         You can now change the colors on any screen and use the AGA's 24 bit
  3. palette.  The only major change over the last palette requester I wrote is
  4. that it now uses the actual 3.0 functions LoadRGB32(), and GetRGB32() rather
  5. than my own home brewed versions.  You will also notice the additions of
  6. Keyboard equivalents, and "R", "G", and "B" by the sliders, and the addition
  7. of a "Selected Color" box on the left side of the Palette gadget.
  8.  
  9.         By the way, I am not rich, but I am not doing this for money
  10.     either.  All I ask is if you use or modify this program let me know.
  11.     I am really interested in seeing how far this program gets.
  12.     Do what you want with it.
  13.  
  14.         But if it makes you fell better, I will take cash  :-))
  15.         You can guesse the legal matters, "I am not responsible..."
  16.  
  17.                 Psychotic Psoftware
  18.                 Anthony J. Moringello
  19.                 2209 E. Park Pl. #4
  20.                 Miwlaukee, WI  53211
  21. ----------------------------------------------------------------------*/
  22. /*
  23.  *  Source machine generated by GadToolsBox V2.0
  24.  *  which is (c) Copyright 1991-1993 Jaba Development
  25.  *
  26.  *  GUI Designed by : Anthony J. Moringello - anthonym@csd4.csd.uwm.edu
  27.  */
  28.  
  29. #include <exec/types.h>
  30. #include <Exec/Memory.h>
  31. #include <intuition/intuition.h>
  32. #include <Intuition/IntuitionBase.h>
  33. #include <intuition/classes.h>
  34. #include <intuition/classusr.h>
  35. #include <intuition/imageclass.h>
  36. #include <intuition/gadgetclass.h>
  37. #include <libraries/gadtools.h>
  38. #include <graphics/displayinfo.h>
  39. #include <graphics/gfxbase.h>
  40. #include <clib/exec_protos.h>
  41. #include <clib/intuition_protos.h>
  42. #include <clib/gadtools_protos.h>
  43. #include <clib/graphics_protos.h>
  44. #include <clib/utility_protos.h>
  45. #include <CLib/AGA_Protos.h>
  46. #include <string.h>
  47.  
  48. extern struct ExecBase    **SysBase;
  49. extern struct IntuitionBase    *IntuitionBase;
  50. extern struct GfxBase    *GfxBase;
  51. extern struct GadToolsBase    *GadToolsBase;
  52.  
  53. #include <pragmas/exec_pragmas.h>
  54. #include <pragmas/intuition_pragmas.h>
  55. #include <pragmas/gadtools_pragmas.h>
  56. #include <pragmas/graphics_pragmas.h>
  57. #include <pragmas/utility_pragmas.h>
  58. #include <Pragmas/AGA_Pragmas.h>
  59.  
  60. #include "Palette.h"
  61.  
  62. struct Screen         *Scr = NULL;
  63. struct Window         *PReqWnd = NULL;
  64. struct Gadget         *PReqGList = NULL;
  65. struct IntuiMessage    PReqMsg;
  66. struct Gadget         *PReqGadgets[7];
  67. APTR                   VisualInfo = NULL;
  68. UWORD                  PReqWidth = 300;
  69. UWORD                  PReqHeight = 189;
  70. UBYTE                 *PReqWdt = (UBYTE *)"24 Bit Palette Requester";
  71.  
  72. ULONG  red, green, blue;
  73. ULONG  index, ncolors;
  74. ULONG  table[2+3];
  75. ULONG  *originalpalette;  // Allocate later for depth of screen
  76. int    ResetPalette(void);
  77. int    SetTable(void);
  78.  
  79. struct TextAttr topaz8 = {
  80.     ( STRPTR )"topaz.font", 8, 0x00, 0x01 };
  81.  
  82. UWORD PReqGTypes[] = {
  83.     SLIDER_KIND,
  84.     SLIDER_KIND,
  85.     SLIDER_KIND,
  86.     BUTTON_KIND,
  87.     BUTTON_KIND,
  88.     BUTTON_KIND,
  89.     PALETTE_KIND
  90. };
  91.  
  92. struct NewGadget PReqNGad[] = {
  93.     24, 169, 243, 14, (UBYTE *)"_B", NULL, GD_BlueSliderG, PLACETEXT_LEFT, NULL, (APTR)BlueSliderGClicked,
  94.     24, 152, 243, 14, (UBYTE *)"_G", NULL, GD_GreenSliderG, PLACETEXT_LEFT, NULL, (APTR)GreenSliderGClicked,
  95.     24, 135, 243, 14, (UBYTE *)"_R", NULL, GD_RedSliderG, PLACETEXT_LEFT, NULL, (APTR)RedSliderGClicked,
  96.     2, 97, 86, 32, (UBYTE *)"_Use", NULL, GD_UseG, PLACETEXT_IN, NULL, (APTR)UseGClicked,
  97.     104, 97, 86, 32, (UBYTE *)"r_Eset", NULL, GD_ResetG, PLACETEXT_IN, NULL, (APTR)ResetGClicked,
  98.     203, 97, 86, 32, (UBYTE *)"_Cancel", NULL, GD_CancelG, PLACETEXT_IN, NULL, (APTR)CancelGClicked,
  99.     51, 3, 238, 90, NULL, NULL, GD_PaletteG, 0, NULL, (APTR)PaletteGClicked
  100. };
  101.  
  102. ULONG PReqGTags[] = {
  103.     (GTSL_Max), 255, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%2lX", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  104.     (GTSL_Max), 255, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%2lX", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  105.     (GTSL_Max), 255, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%2lX", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  106.     (GT_Underscore), '_', (TAG_DONE),
  107.     (GT_Underscore), '_', (TAG_DONE),
  108.     (GT_Underscore), '_', (TAG_DONE),
  109.     (GTPA_Depth), 8, (TAG_DONE)
  110. };
  111.  
  112. void PReqRender( void )
  113. {
  114.     UWORD        offx, offy;
  115.  
  116.     offx = PReqWnd->BorderLeft;
  117.     offy = PReqWnd->BorderTop;
  118.  
  119.  
  120.     DrawBevelBox( PReqWnd->RPort, offx + 3, offy + 26, 45, 39, GT_VisualInfo, VisualInfo, TAG_DONE );
  121.     DrawBevelBox( PReqWnd->RPort, offx + 7, offy + 28, 37, 35, GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  122. }
  123.  
  124. int HandlePReqIDCMP( void )
  125. {
  126.     struct IntuiMessage    *m;
  127.     int            (*func)(struct IntuiMessage *);
  128.     BOOL            running = TRUE;
  129.  
  130.     while( m = GT_GetIMsg( PReqWnd->UserPort )) {
  131.  
  132.         CopyMem(( char * )m, ( char * )&PReqMsg, (long)sizeof( struct IntuiMessage ));
  133.  
  134.         GT_ReplyIMsg( m );
  135.  
  136.         switch ( PReqMsg.Class ) {
  137.  
  138.             case    IDCMP_REFRESHWINDOW:
  139.                 GT_BeginRefresh( PReqWnd );
  140.                 PReqRender();
  141.                 GT_EndRefresh( PReqWnd, TRUE );
  142.                 break;
  143.  
  144.             case    IDCMP_CLOSEWINDOW:
  145.                 running = PReqCloseWindow();
  146.                 break;
  147.  
  148.             case    IDCMP_VANILLAKEY:
  149.                 switch(PReqMsg.Code)
  150.                 {
  151.                     case 'u':
  152.                     case 'U':
  153.                         running = FALSE;
  154.                         break;
  155.                     case 'e':
  156.                     case 'E':
  157.                               ResetPalette();
  158.                         running = TRUE;
  159.                         break;
  160.                     case 'c':
  161.                     case 'C':
  162.                         ResetPalette();
  163.                         running = FALSE;
  164.                         break;
  165.                     case 'r':
  166.                         red = (++red)&0xFF;
  167.                         GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL, GTSL_Level, red, TAG_END);
  168.                               SetTable();
  169.                               break;
  170.                          case 'R':
  171.                              red = (--red)&0xFF;
  172.                              GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL, GTSL_Level, red, TAG_END);
  173.                              SetTable();
  174.                              break;
  175.                     case 'g':
  176.                         green = (++green)&0xFF;
  177.                         GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL, GTSL_Level, green, TAG_END);
  178.                               SetTable();
  179.                               break;
  180.                          case 'G':
  181.                              green = (--green)&0xFF;
  182.                              GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL, GTSL_Level, green, TAG_END);
  183.                              SetTable();
  184.                              break;
  185.                     case 'b':
  186.                         blue = (++blue)&0xFF;
  187.                         GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL, GTSL_Level, blue, TAG_END);
  188.                               SetTable();
  189.                               break;
  190.                          case 'B':
  191.                              blue = (--blue)&0xFF;
  192.                              GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL, GTSL_Level, blue, TAG_END);
  193.                              SetTable();
  194.                              break;
  195.                              
  196.                          default:    
  197.                              break;
  198.                     }
  199.                     break;
  200.  
  201.             case IDCMP_MOUSEMOVE:
  202.             case    IDCMP_GADGETUP:
  203.             case    IDCMP_GADGETDOWN:
  204.                 func = ( void * )(( struct Gadget * )PReqMsg.IAddress )->UserData;
  205.                 running = func(&PReqMsg);
  206.                 break;
  207.         }
  208.     }
  209.     return( running );
  210. }
  211.  
  212. int OpenPReqWindow( void )
  213. {
  214.     struct NewGadget    ng;
  215.     struct Gadget    *g;
  216.     UWORD        lc, tc;
  217.     UWORD        offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  218.  
  219.     if ( ! ( g = CreateContext( &PReqGList )))
  220.         return( 1L );
  221.  
  222.     for( lc = 0, tc = 0; lc < PReq_CNT; lc++ ) {
  223.  
  224.         CopyMem((char * )&PReqNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  225.  
  226.         ng.ng_VisualInfo = VisualInfo;
  227.         ng.ng_TextAttr   = &topaz8;
  228.         ng.ng_LeftEdge  += offx;
  229.         ng.ng_TopEdge   += offy;
  230.  
  231.         PReqGadgets[ lc ] = g = CreateGadgetA((ULONG)PReqGTypes[ lc ], g, &ng, ( struct TagItem * )&PReqGTags[ tc ] );
  232.  
  233.         while( PReqGTags[ tc ] ) tc += 2;
  234.         tc++;
  235.  
  236.         if ( NOT g )
  237.             return( 2L );
  238.     }
  239.  
  240.     if ( ! ( PReqWnd = OpenWindowTags( NULL,
  241.                 WA_Left,    0,
  242.                 WA_Top,        0,
  243.                 WA_Width,    PReqWidth,
  244.                 WA_Height,    PReqHeight + offy,
  245.                 WA_IDCMP,    SLIDERIDCMP|BUTTONIDCMP|PALETTEIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_MOUSEMOVE|IDCMP_VANILLAKEY,
  246.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  247.                 WA_Gadgets,    PReqGList,
  248.                 WA_Title,    PReqWdt,
  249.                 WA_ScreenTitle,    "24 Bit Palette Requester © Anthony J. Moringello",
  250.                 WA_PubScreen,    Scr,
  251.                 TAG_DONE )))
  252.     return( 4L );
  253.  
  254.     GT_RefreshWindow( PReqWnd, NULL );
  255.  
  256.     PReqRender();
  257.  
  258.     return( 0L );
  259. }
  260.  
  261. void ClosePReqWindow( void )
  262. {
  263.     if ( PReqWnd        ) {
  264.         CloseWindow( PReqWnd );
  265.         PReqWnd = NULL;
  266.     }
  267.  
  268.     if ( PReqGList      ) {
  269.         FreeGadgets( PReqGList );
  270.         PReqGList = NULL;
  271.     }
  272. }
  273.  
  274. /*-------------  Now actually do stuff when events come in.  ----------------*/
  275. #include "Palette_Temp.c"
  276.  
  277. VOID
  278. main()
  279. {
  280.     BOOL  running = TRUE;
  281. //    struct EasyStruct    es;
  282.  
  283.  
  284.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
  285.     if( IntuitionBase )
  286.     {
  287.         GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39);
  288.         if( GfxBase )
  289.         {
  290.             GadToolsBase = (struct GadToolsBase *)OpenLibrary("gadtools.library", 37);
  291.             if( GadToolsBase )
  292.             {
  293.                 Scr = IntuitionBase->FirstScreen;
  294.                 if( (VisualInfo = GetVisualInfo( Scr, TAG_DONE)) )
  295.                 {
  296.                     ncolors = 1<< Scr->BitMap.Depth;
  297.                     PReqGTags[61] = Scr->BitMap.Depth;
  298.                         OpenPReqWindow();
  299.                         if( PReqWnd )
  300.                         {
  301.                             originalpalette = AllocVec(8+ 12*ncolors, MEMF_ANY|MEMF_CLEAR);
  302.                             if( originalpalette )
  303.                             {
  304.                             GetRGB32(Scr->ViewPort.ColorMap, 0, ncolors, &originalpalette[1]);
  305.                             originalpalette[0] = ncolors<<16 + 0;
  306.                                   ResetPalette();
  307.                                 while( running )
  308.                                 {
  309.                                       Wait(1L<<PReqWnd->UserPort->mp_SigBit);
  310.                                     running = HandlePReqIDCMP();
  311.                                 }
  312.                            }
  313.                             FreeVec(originalpalette);
  314.                             ClosePReqWindow();
  315.                        }
  316.                     FreeVisualInfo( VisualInfo );
  317.                     VisualInfo = NULL;
  318.                 }
  319.                    CloseLibrary((struct Library *)GadToolsBase);
  320.                }
  321.               CloseLibrary((struct Library *)GfxBase);
  322.           }
  323. /*----------------------------------------------------------------------------
  324.           else
  325.           {
  326.               if( GfxBase->LibNode.dl_lib.Version < 39 )
  327.             {
  328.                 es.es_StructSize = sizeof(struct EasyStruct)
  329.                 es.es_Flags = NULL;
  330.                 es.es_Title = "Palette Req Error!";
  331.                 es.es_TextFormat = "You need version 39 of Gfx Library.";
  332.                 es.es_GadgetFormat = "OK";
  333.  
  334.                 EasyRequest( etc....
  335. ------------------------------------------------------------------------------*/
  336.          CloseLibrary((struct Library *)IntuitionBase);
  337.      }
  338. }
  339.  
  340. int
  341. ResetPalette(void)
  342. {
  343.     LoadRGB32(&Scr->ViewPort, originalpalette);
  344.     GetRGB32(Scr->ViewPort.ColorMap, index, 1, &table[1]);
  345.     red   = table[1]>>24;
  346.     green = table[2]>>24;
  347.     blue  = table[3]>>24;
  348.     SetAPen(PReqWnd->RPort, index);
  349.     RectFill(PReqWnd->RPort, PReqWnd->BorderLeft+9, PReqWnd->BorderTop+29,
  350.                                  PReqWnd->BorderLeft+41, PReqWnd->BorderTop+61);
  351.      GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL,
  352.                        GTSL_Level, red, TAG_END);
  353.      GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL,
  354.                        GTSL_Level, green, TAG_END);
  355.      GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL,
  356.                        GTSL_Level, blue, TAG_END);
  357.     return(0);
  358. }
  359.